HealthWorkout PRO
The HealthWorkout class provides a high-level interface for accessing and analyzing workout data from Apple Health. A workout represents a full session of physical activity, such as running, swimming, or cycling, recorded between a start and end time, and may include additional events and aggregated statistics.
Use Cases
- Retrieve and display workout history
- Analyze workout types and durations
- Correlate workout sessions with metrics such as heart rate, calories burned, or distance
- Visualize workout events like pauses, resumes, laps, and segments
- Access health statistics collected during the workout session
Properties
Related Types
HealthWorkoutActivityType
Represents the type of physical activity, such as:
runningwalkingcyclingswimmingyoga- ... and many more (see
HealthWorkoutActivityTypedocumentation)
HealthWorkoutEvent
Represents a specific event during the workout, such as:
- pause
- resume
- motion paused/resumed
- lap or segment markers
HealthStatistics
Provides calculated metrics such as:
averageQuantity()sumQuantity()maximumQuantity()minimumQuantity()mostRecentQuantity()
These are based on health data samples (e.g., heart rate, energy burned) during the workout's time interval.
Example Usage
Notes
HealthWorkoutinstances are typically retrieved using query APIs such asHealth.queryWorkouts()(if available in the framework).- The
allStatisticsproperty provides quick access to summary data without needing to query samples manually. - Use the
workoutEventsproperty to reconstruct the timeline of activity (e.g., when the user paused or resumed).
